home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 October / DPPCPRO1005.ISO / Download / Web Developer / webdeveloper.xpi / chrome / webdeveloper.jar / content / webdeveloper / outline.js < prev    next >
Encoding:
JavaScript  |  2005-03-21  |  9.1 KB  |  195 lines

  1. // Ignores the click event
  2. function webdeveloper_ignoreClick(event)
  3. {
  4.     // If there is an event target and the click was not a right click
  5.     if(event.target && event.button != 2)
  6.     {
  7.         event.preventDefault();
  8.     }
  9. }
  10.  
  11. // Outlines all block level elements
  12. function webdeveloper_outlineBlockLevelElements(element, applyStyle)
  13. {
  14.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  15.  
  16.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_block_level_elements.css", "webdeveloper-outline-block-level-elements", applyStyle);
  17.  
  18.     // If the show outlined element names preference is set
  19.     if(preferencesService.prefHasUserValue("webdeveloper.outline.show.element.names") && preferencesService.getBoolPref("webdeveloper.outline.show.element.names"))
  20.     {
  21.         webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_block_level_elements_before.css", "webdeveloper-outline-block-level-elements-before", applyStyle);
  22.         webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-outline-block-level-elements-before-tooltips", "*:before");
  23.     }
  24. }
  25.  
  26. // Outlines the given element
  27. function webdeveloper_outlineCustomElements(element)
  28. {
  29.     webdeveloper_outlinedElements = new Array();
  30.  
  31.     // If the menu is checked
  32.     if(element.getAttribute("checked"))
  33.     {
  34.         window.openDialog("chrome://webdeveloper/content/dialogs/outline_elements.xul", "webdeveloper-outline-elements-dialog", "centerscreen,chrome,modal", webdeveloper_outlinedElements);
  35.  
  36.         // If the user clicked cancel in the dialog
  37.         if(webdeveloper_outlinedElements.length == 0)
  38.         {
  39.            element.removeAttribute("checked");
  40.         }
  41.     }
  42.  
  43.     webdeveloper_outlineElements(element, true);
  44. }
  45.  
  46. // Outlines all deprecated elements
  47. function webdeveloper_outlineDeprecatedElements(element, applyStyle)
  48. {
  49.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  50.  
  51.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_deprecated_elements.css", "webdeveloper-outline-deprecated-elements", applyStyle);
  52.  
  53.     // If the show outlined element names preference is set
  54.     if(preferencesService.prefHasUserValue("webdeveloper.outline.show.element.names") && preferencesService.getBoolPref("webdeveloper.outline.show.element.names"))
  55.     {
  56.         webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_deprecated_elements_before.css", "webdeveloper-outline-deprecated-elements-before", applyStyle);
  57.         webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-outline-deprecated-elements-before-tooltips", "*:before");
  58.     }
  59. }
  60.  
  61. // Outlines the given element
  62. function webdeveloper_outlineElements(element, applyStyle)
  63. {
  64.     // If the menu is checked
  65.     if(element.getAttribute("checked") && webdeveloper_outlinedElements.length > 0)
  66.     {
  67.         const mainTabBox         = getBrowser().mTabBox;
  68.         const documentList       = webdeveloper_getDocuments(getBrowser().browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  69.         const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  70.  
  71.         var headElementList     = null;
  72.         var outlineColor        = null;
  73.         var outlineElement      = null;
  74.         var outlineElementList  = null;
  75.         var outlineElementValue = null;
  76.         var pageDocument        = null;
  77.         var styleElement        = null;
  78.  
  79.         // Loop through the documents
  80.         for(var i = 0; i < documentList.length; i++)
  81.         {
  82.             pageDocument    = documentList[i];
  83.             headElementList = pageDocument.getElementsByTagName("head");
  84.             styleElement    = pageDocument.createElement("style");
  85.  
  86.             styleElement.setAttribute("id", "webdeveloper-outline-custom-elements");
  87.             styleElement.setAttribute("type", "text/css");
  88.  
  89.             // Loop through outline colors and elements
  90.             for(var j = 0; j <= 5; j++)
  91.             {
  92.                 outlineColor   = "webdeveloper.custom." + j + ".color";
  93.                 outlineElement = "webdeveloper.custom." + j + ".element";
  94.  
  95.                 // If the color and element are set and not blank
  96.                 if(preferencesService.prefHasUserValue(outlineColor) && preferencesService.prefHasUserValue(outlineElement) && preferencesService.getComplexValue(outlineColor, Components.interfaces.nsISupportsString).data.trim() != "" && preferencesService.getComplexValue(outlineElement, Components.interfaces.nsISupportsString).data.trim() != "")
  97.                 {
  98.                     outlineElementList = preferencesService.getComplexValue(outlineElement, Components.interfaces.nsISupportsString).data.trim().split(",");
  99.  
  100.                     // Loop through the elements
  101.                     for(var k = 0; k < outlineElementList.length; k++)
  102.                     {
  103.                         outlineElementValue = outlineElementList[k];
  104.                         styleElement.appendChild(pageDocument.createTextNode(outlineElementValue + " { -moz-outline: 1px solid " + preferencesService.getComplexValue(outlineColor, Components.interfaces.nsISupportsString).data.trim() + " !important; }"));
  105.  
  106.                         // If the show outlined element names preference is set
  107.                         if(preferencesService.prefHasUserValue("webdeveloper.outline.show.element.names") && preferencesService.getBoolPref("webdeveloper.outline.show.element.names"))
  108.                         {
  109.                             styleElement.appendChild(pageDocument.createTextNode(outlineElementValue + ":before { content: \"<" + outlineElementValue + ">\" !important; }"));
  110.                         }
  111.                     }
  112.                 }
  113.             }
  114.  
  115.             // If there is a head element
  116.             if(headElementList.length > 0)
  117.             {
  118.                 headElementList[0].appendChild(styleElement);
  119.             }
  120.             else
  121.             {
  122.                 pageDocument.documentElement.appendChild(styleElement);
  123.             }
  124.         }
  125.  
  126.         // If applying styles
  127.         if(applyStyle)
  128.         {
  129.             webdeveloper_addAppliedStyle("webdeveloper-outline-custom-elements");
  130.         }
  131.     }
  132.     else
  133.     {
  134.         webdeveloper_removeStyleSheet("webdeveloper-outline-custom-elements", true);
  135.     }
  136.  
  137.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/before.css", "webdeveloper-outline-custom-elements-before", applyStyle);
  138.     webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-outline-custom-elements-before-tooltips", "*:before");
  139. }
  140.  
  141. // Outlines all frames
  142. function webdeveloper_outlineFrames(element, applyStyle)
  143. {
  144.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_frames.css", "webdeveloper-outline-frames", applyStyle);
  145. }
  146.  
  147. // Outlines all the links without title attributes
  148. function webdeveloper_outlineLinksWithoutTitleAttributes(element, applyStyle)
  149. {
  150.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_links_without_title_attributes.css", "webdeveloper-outline-links-without-title-attributes", applyStyle);
  151. }
  152.  
  153. // Outlines the selected element
  154. function webdeveloper_outlineSelectedElement(element, applyStyle)
  155. {
  156.     const mainTabBox   = getBrowser().mTabBox;
  157.     const documentList = webdeveloper_getDocuments(getBrowser().browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  158.  
  159.     var checked      = element.getAttribute("checked");
  160.     var pageDocument = null;
  161.  
  162.     // Loop through the documents
  163.     for(var i = 0; i < documentList.length; i++)
  164.     {
  165.         pageDocument = documentList[i];
  166.  
  167.         // If outlining the selected element
  168.         if(checked)
  169.         {
  170.             pageDocument.addEventListener("mouseover", webdeveloper_displayElementAncestors, true);
  171.             pageDocument.addEventListener("click", webdeveloper_ignoreClick, true);
  172.         }
  173.         else
  174.         {
  175.             pageDocument.removeEventListener("mouseover", webdeveloper_displayElementAncestors, true);
  176.             pageDocument.removeEventListener("click", webdeveloper_ignoreClick, true);
  177.             getBrowser().contentWindow.status = null;
  178.         }
  179.     }
  180.  
  181.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_selected_element.css", "webdeveloper-outline-selected-element", applyStyle);
  182. }
  183.  
  184. // Outlines all table cells
  185. function webdeveloper_outlineTableCells(element, applyStyle)
  186. {
  187.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_table_cells.css", "webdeveloper-outline-table-cells", applyStyle);
  188. }
  189.  
  190. // Outlines all tables
  191. function webdeveloper_outlineTables(element, applyStyle)
  192. {
  193.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_tables.css", "webdeveloper-outline-tables", applyStyle);
  194. }
  195.